package com.runvp.service.biz.handler;

import com.runvp.common.enums.BillChangeType;
import com.runvp.common.enums.TranType;
import com.runvp.service.biz.domain.BizCustomerTranLog;
import com.runvp.service.biz.domain.BizOrder;
import com.runvp.service.biz.service.IBizCustomerWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
public class CmdCommonHandler {


    @Autowired
    private IBizCustomerWalletService bizCustomerWalletService;
    /**
     * 消费记录
     * @param order
     */
    @Transactional(rollbackFor = Exception.class)
    public void buildCustomerTranLog(String opMsg,BizOrder order){
        //余额扣款
        BizCustomerTranLog bizCustomerTranLog = new BizCustomerTranLog();
        bizCustomerTranLog.setCustomerId(order.getCustomerId());
        bizCustomerTranLog.setTranFee(order.getAmount());
        bizCustomerTranLog.setPayFee(order.getAmount());
        bizCustomerTranLog.setTranNo(order.getOrderNo());
        bizCustomerTranLog.setCreateBy(order.getCreateBy());
        bizCustomerTranLog.setPayChannel(order.getType());
        bizCustomerTranLog.setBillChangeType(BillChangeType.OUT.getCode());
        bizCustomerTranLog.setTranType(TranType.BUY.getCode());
        bizCustomerTranLog.setRemark(TranType.BUY.getDesc());
        bizCustomerWalletService.rechargeSave(opMsg, bizCustomerTranLog);
    }
    /**
     * 消费记录
     * @param order
     */
    @Transactional(rollbackFor = Exception.class)
    public void buildCustomerRefundTranLog(String opMsg,BizOrder order){
        //余额扣款
        BizCustomerTranLog bizCustomerTranLog = new BizCustomerTranLog();
        bizCustomerTranLog.setCustomerId(order.getCustomerId());
        bizCustomerTranLog.setTranFee(order.getAmount());
        bizCustomerTranLog.setPayFee(order.getAmount());
        bizCustomerTranLog.setTranNo(order.getOrderNo());
        bizCustomerTranLog.setCreateBy(order.getCreateBy());
        bizCustomerTranLog.setPayChannel(order.getType());
        bizCustomerTranLog.setBillChangeType(BillChangeType.IN.getCode());
        bizCustomerTranLog.setTranType(TranType.RECOVERY_IN.getCode());
        bizCustomerTranLog.setRemark(TranType.RECOVERY_IN.getDesc());
        bizCustomerWalletService.rechargeSave(opMsg, bizCustomerTranLog);
    }
}
